<# .SYNOPSIS GroupChecker : check a Mult-IP group client count, and send an email if greater than previous count. (c)2013 Radio IP Software inc. Version 1.0 - DO NOT DISTRIBUTE .EXAMPLE C:\PS>.\GroupChecker.ps1 -to myemail@mydomain.com -from multip1@mydomain.com -delay 60 -smtpserver exchg.mydomain.com .DESCRIPTION Running the GroupChecker.ps1 script will send an email when the client count of a specified group is greater than the previous count. This script loops indifinitly. Use the -detail option of get-help to see help on parameters. #> [cmdletbinding()] param ( #Provide the mailbox name for the source (From) email address [parameter(Mandatory=$true)][string]$from, #Provide the mailbox name for the destination (To) email address [parameter(Mandatory=$true)][string]$to, #Provie the mail server name or IP adress [parameter(Mandatory=$true)][string]$smtpServer, #Provide the group to check (default is 'Quarantine') [parameter(Mandatory=$false)][string]$group = "Quarantine", #Provide the delay, in seconds, between each checking loop (default = 30 seconds) [int32]$delay = 30, #Send a test email, and do not check the group client count. [parameter(Mandatory=$false)][switch]$test=$false ) $thisComputer = $env:COMPUTERNAME; if($test) { $body = @" This message has been sent by the GroupChecker Powershell script, from server '$thisComputer'. Please disregard this message. Regards. "@ send-mailmessage -from $from -to $to -subject "Test: New Client(s) in '$group'" -Body $body -smtpserver $smtpServer; exit; } # Connect to Mult-IP Server try { $a = new-object -com radioip.therock; $a.OpenSession($null,$null,$null); } catch { write-Host "Can't find Mult-IP Gateway"; exit; } #Initialize variables $Qcount = 0; $PrevQcount = 0; $firstLoop = $true; while($true) { $Qcount = $a.groups.item($group).clients.count; if($Qcount -ne $PrevQcount) { write-debug "$Qcount Client(s) In $group"; if($Qcount -gt $PrevQcount) { $diff = $PrevQcount - $Qcount; $clients = $a.groups.item($group).clients; $out = ""; $clients | ForEach-Object { $name = $_.ClientName; $out += "`t$name`n"; } if($firstLoop) { $subject = "GroupChecker script started on $thisComputer - $QCount clients in '$group'" $body = @" GroupChecker script started successfully on server $thisComputer. There are currently $Qcount Mult-IP clients in the '$group' group: $out "@; } else { $subject = "$thisComputer - $diff New Client(s) in '$group'"; $body = @" $diff Mult-IP clients were added to the '$group' group, for a total of $Qcount clients: $out "@; } send-mailmessage -from $from -to $to -subject $subject -body $body -smtpserver $smtpServer; Write-Debug "Mail was sent"; } $PrevQcount = $Qcount; } start-sleep -seconds $delay; }